package com.jilin.library.controller;

import com.jilin.library.entity.Book;
import com.jilin.library.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/books")
@CrossOrigin
public class BookController {
    @Autowired
    private BookService bookService;
    
    @GetMapping
    public List<Book> getAllBooks() {
        return bookService.findAll();
    }
    
    @PostMapping
    public Book addBook(@RequestBody Book book) {
        return bookService.addBook(book);
    }
    
    @PutMapping("/{id}/stock")
    public int updateStock(@PathVariable Integer id, @RequestParam Integer quantity) {
        return bookService.updateStock(id, quantity);
    }
} 